<?php

class Admin_QuestionController extends Zend_Controller_Action
{

    public function init()
    {
        $auth_session = new Zend_Session_Namespace('Auth');
        if (!isset($auth_session->user)) {
        	$this->_helper->redirector->gotoRoute(array('action' => 'login', 'controller' => 'auth'), 'admin', true);
        }
    }

    public function indexAction()
    {
        // action body
    }

    public function addAction()
    {
    	$request = $this->getRequest();
    	$options = $request->getParam('options', null);
    	$option_count = 4;
    	if (isset($options)) $option_count = (sizeof($options) / 3);
        $form = new Admin_Form_Question($option_count);
        $option_template = $form->options->o1->render();
        $option_template .= $form->options->n1->render();
        $option_template .= $form->options->a1->render();
        $option_template .= $form->options->c1;
        $option_template = addslashes($option_template);
        $option_template = str_replace(PHP_EOL, '', $option_template);
        $this->view->form = $form;
        $this->view->option_template = $option_template;
        $this->view->option_count = $option_count;
        $this->view->headLink()->appendStylesheet($this->view->baseUrl('admin/css/form.css'));
        $this->view->headScript()->appendFile('//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js');
        $this->view->headScript()->appendFile($this->view->baseUrl('admin/js/add_edit_question.js'));
        
        if ($request->isPost()) {
        	$form_data = $request->getPost();
        	if ($form->isValid($form_data)) {
        		var_dump($form_data);
        	}
        }
    }


}



